<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SfShopCoupon;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SfShopCouponController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SfShopCoupon(), function (Grid $grid) {
            $grid->column('coupon_id')->sortable();
            $grid->column('coupon_nick');
            $grid->column('coupon_type');
            $grid->column('coupon_low');
            $grid->column('coupon_value');
            $grid->column('usable_range');
            $grid->column('limit_type');
            $grid->column('indate');
            $grid->column('indate_time');
            $grid->column('coupon_repertory');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('coupon_id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SfShopCoupon(), function (Show $show) {
            $show->field('coupon_id');
            $show->field('coupon_nick');
            $show->field('coupon_type');
            $show->field('coupon_low');
            $show->field('coupon_value');
            $show->field('usable_range');
            $show->field('limit_type');
            $show->field('indate');
            $show->field('indate_time');
            $show->field('coupon_repertory');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SfShopCoupon(), function (Form $form) {
            $form->display('coupon_id');
            $form->text('coupon_nick');
            $form->radio('coupon_type','优惠券类型')->options([
                '1'=>'满减券',
                '2'=>'立减券'
            ]);
            $form->text('coupon_low');
            $form->text('coupon_value');
            $form->radio('usable_range')->options([
                '1'=>'商品可用',
                '2'=>'商家品类可用',
                '3'=>'商家可用',
                '4'=>'平台品类可用',
                '5'=>'全平台可用',
            ]);
            $form->radio('limit_type')->options([
                '1'=>'同享',
                '2'=>'互斥',
            ]);
            $form->radio('indate')->options([
                '1'=>'临时',
                '2'=>'固定时间',
            ]);
            $form->number('indate_time');
            $form->number('coupon_repertory');
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
